﻿using InventoryIssue.API.Write.Application.Command.Allocate;
using InventoryIssue.API.Write.Application.Command.Stocktaking;
using InventoryIssue.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace InventoryIssue.API.Write.Controllers
{
    /// <summary>
    /// 调拨控制器 - 调拨管理模块
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class AllocateController : ControllerBase
    {
        private readonly IMediator mediator;

        public AllocateController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        
        /// <summary>
        /// 新增调拨信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> CreateAllocate(CreateAllocateCommand request)
        {
            return await mediator.Send(request);
        }
        
        /// <summary>
        /// 删除调拨信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<int>> DelAllocate([FromQuery]DelAllocateCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 创建调拨单操作记录 - 调拨管理模块
        /// 记录调拨单的状态变更和操作历史
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> CreateOperationRecord(CreateOperationRecordCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 编辑调拨单+操作记录
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> UpdateAllocateStatus(UpdateAllocateStatusCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 审核调拨单+操作记录
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> ApproveAllocate(ApprovalAllocateCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 取消调拨单中
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> CancelAllocate(CancelAllocateCommand request)
        {
            return await mediator.Send(request);
        }

       
    }
}
